package com.mairuide._frame.utils.excellistener;

import com.mairuide.bill.DealFlow;
import com.mairuide.bill.DealFlowService;
import com.mairuide.bill.titlepool.DealFlowTitleService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther 刘中华
 * @create 2019-04-11 9:26
 * 特殊的模板匹配，没用sax的方法。单纯的调用封装下
 */
@Component
public class SpecialTemplate {
    @Autowired
    private DealFlowTitleService dealFlowTitleService;
    @Autowired
    DealFlowService dealFlowService;
    private Map<String,Object> paraMap = new HashMap<String,Object>();  //参数MAP

    /**
     * @Author 刘中华
     * @Date 2019/4/11 9:28 
     * @Param 处理邮政
     * @return
     * @Description
     **/
    public Map<String, Object> getYouZhengTemplate(Workbook wb,Map paraMap){
        Map<String,Object> resultMap = new HashMap<String,Object>();  //结果MAP
        this.paraMap=paraMap;
        List<DealFlow> list = null;
        list = dealFlowTitleService.youZhengTemplate(wb);
        doSomething(list);
        resultMap.put("successNum",list.size());
        return resultMap;
    }

    private void doSomething(List<DealFlow> data){
        for (int i = 0; i < data.size(); i++) {
            DealFlow dealFlow = data.get(i);
            dealFlow.setUuid((String)paraMap.get("uuid"));
            dealFlow.setCasemanageId((String)paraMap.get("uid"));
            dealFlow.setCreateId((Integer) paraMap.get("platManagerId"));
            dealFlow.setCreateTime(new Timestamp(System.currentTimeMillis()));
            dealFlow.setIsDelete(0);
        }
        dealFlowService.batchSave(data);
    }
}
